package com.example.mybatisplusdemo.Methods;


import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class methods {
    /**
     * md5 加密
     * @param str
     * @return String
     */
    public String md5(String str){
        String md5 = "";
        md5 = DigestUtils.md5DigestAsHex(str.getBytes(StandardCharsets.UTF_8));
        return md5;
    }

    /**
     * 生成指定长度随机字符串
     * @param length
     * @return string
     */
    public String randomstr(int length){
        String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();
        StringBuffer stringBuffer = new StringBuffer();
        for(int i=0;i<length;i++){
            int number=random.nextInt(62);
            stringBuffer.append(str.charAt(number));
        }
        return stringBuffer.toString();
    }

    /**
     * 检查长度是否符合要求
     * @param str
     * @param length1
     * @param length2
     * @return
     */
    public boolean checklenth(String str,int length1,int length2){
        return (str.length() <= length2 && str.length()>=length1);
    }

    /**
     * 显示系统时间
     * @return
     */
    public String getSystemTime(){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        return df.format(new Date());
    }

}
